package cn.com.pxto.global.varables;

import java.util.GregorianCalendar;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;

import cn.com.pxto.commons.propertiesutil.ConfigurationException;
import cn.com.pxto.commons.propertiesutil.Properties;

/**
 * ��ֵ��
 */

public class Global {
	public Global() {
		super();
	}

	public static String getServerBasePath(HttpServletRequest request)
	{
		String basePath = request.getScheme() + "://" + request.getServerName();
		if (request.getServerPort() != 80) 
			basePath = basePath + ":" + request.getServerPort();
		basePath = basePath + request.getContextPath() + "/";
		return basePath;
	}
	
	public static ActionMessages getActionMessage(String msg)
	{
	    ActionMessages messages = new ActionMessages();
	    messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(msg));
	    return messages;
	}
	
	public static String getMessage(HttpServletRequest request, String msg)
	{
		MessageResources resources = (MessageResources)request.getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
        String message = resources.getMessage(msg); 
	    return message;
	}

	public static long getRandNumber()
	{
		return (new GregorianCalendar()).getTimeInMillis();
	}
	
	public static int getBasicRoomFee(){
		int basicRoomFee=0;
		try {
//			从配置文件中获取房间基本费
			basicRoomFee = Properties.getInstance().getIntValue("room.basic.fee");
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
		return basicRoomFee;
	}
	public static int getBasicUserFee(){
		int basicUserFee=0;
//		从配置文件中获得用户月租费
		try {
			basicUserFee=Properties.getInstance().getIntValue("user.basic.fee");
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
		return basicUserFee;
	}
}
